package com.hangwei.paperless.adapter;

import android.net.Uri;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.FrameLayout;

import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.Sheet;
import com.hangwei.paperless.view.MainProgressTitle;
import com.twelve.all.adapter.MyAdapter;
import com.twelve.all.net.API;
import com.twelve.all.utils.Tools;

import java.util.List;

/**
 * Created by 张龙臣 on 2020/11/17.
 */

public class HomeAdapter extends MyAdapter<Sheet, BaseViewHolder> {
    public HomeAdapter(@Nullable List<Sheet> data) {
        super(R.layout.item_home, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Sheet item) {
        SimpleDraweeView sdvStatus = helper.itemView.findViewById(R.id.sdvStatus);
        helper.setText(R.id.tvTypeName, Tools.checkedString(item.sheetTypeName + " - " + item.woNo))
                .setText(R.id.tvPN, Tools.checkedString(item.pn))
                .setText(R.id.tvNum, Tools.checkedString(item.number))
                .setText(R.id.tvDes, Tools.checkedString(item.description))
                .setText(R.id.tvSN, Tools.checkedString(item.sn));
        MainProgressTitle mainProgressTitle = new MainProgressTitle(mContext);
        FrameLayout progressContent = helper.itemView.findViewById(R.id.progressContent);
        progressContent.addView(mainProgressTitle.getProgressView());
        mainProgressTitle.refreshViewByStep(item.curExStep);
        progressContent.setVisibility("GeneralRoutingSheet".equals(item.sheetTypeNumber)? View.VISIBLE:View.GONE);
        sdvStatus.setImageURI(API.BASE_URL + item.stateName);
        int pic = R.drawable.progress_writing;
        switch (item.state) {
            case 0:
                pic = R.drawable.progress_writting_1;
                break;
            case 1://变更中
                pic = R.drawable.progress_changing;
                break;
            case 2://编写完成
                pic = R.drawable.progress_writed;
                break;
            case 3://已审核
                pic = R.drawable.progress_reviewed;
                break;
            case 4://已批准
                pic = R.drawable.progress_approved;
                break;
            case 5://已配发
                pic = R.drawable.progress_published;
                break;
            case 6://填报中
                if (item.isForInspection)
                    pic = R.drawable.progress_to_check;
                else
                    pic = R.drawable.progress_fill;
                break;
            case 7://提交处置中
                pic = R.drawable.progress_eng;
                break;
            case 8://填报完成
                pic = R.drawable.progress_fill_finish;
                break;
            case 9://已终止
                pic = R.drawable.progress_stoped;
                break;
            case 10://已归档
                pic = R.drawable.progress_filed;
                break;
        }
        sdvStatus.setImageURI((new Uri.Builder()).scheme("res").path(String.valueOf(pic)).build());
        helper.addOnClickListener(R.id.itemView);
    }
}
